package van.planifolia.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import van.planifolia.service.PermissionService;
import van.planifolia.vo.ComResult;

import javax.annotation.Resource;

/**
 * Created by Intellij IDEA<br>
 * 权限的Controller层
 * @author Planifolia.Van
 * @version 1.0
 * @date 2022/10/10 15:55
 */
@RestController
@RequestMapping("/Per")
public class PermissionController {

    @Resource(name = "permissionService")
    private PermissionService permissionService;

    /**
     * 获取当前登录权限的Controller
     * @return 公共的返回结果集
     */
    @RequestMapping("/AllPer")
    public ComResult getAllPermission(){
        return new ComResult(2000,"查询成功",permissionService.getUserPermission());
    }

    /**
     * 活动当前角色的权限树形关系
     * @param rid 当前的角色id
     * @return 公共的结果集
     */
    @RequestMapping("/RolePer")
    public ComResult getRoleRer(Integer rid){
        return new ComResult(2000,"查询成功",permissionService.getRolePermission(rid));
    }

    /**
     * 修改当前角色的权限
     * @param rid 角色id
     * @param pers 权限们
     * @return 公共的结果集
     */
    @RequestMapping("/ModifyUserPer")
    public ComResult modifyUserPer(Integer rid,Integer[] pers){
        if (permissionService.modifyRolePermission(rid, pers)){
            return new ComResult(2000,"修改成功");
        }else {
            return new ComResult(5000,"修改失败");
        }
    }
}
